package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server extends Thread {
	private ServerSocket ss;

	public void run() {
		ss = null;
		try {
			ss = new ServerSocket(Constants.PORT);
		} catch (IOException e) {
			System.out.println("Could not create serversocket.");
		}

		while (!ss.isClosed()) {
			try {
				Socket connection = ss.accept();
				new Connection(connection).start();
			} catch (IOException e) {
			}
		}
	}

	public synchronized void killServer() {
		try {
			ss.close();
		} catch (IOException e) {
			System.exit(1);
		}
	}
}